#include "led.h"
#include "key.h"
#include "delay.h"
#include "usart.h"
#include <stdio.h>
#include "tim3.h"

// 设置全局状态，表示按键按下
uint8_t isAdd   = 0;
uint8_t isMinus = 0;

int main(void)
{
    // 初始化
    USART_Init();
    TIM3_Init();
    Key_Init();

    printf("general timer program start\n");

    // 开启定时器
    TIM3_Start();

    // 定义占空比和变化方向
    uint8_t dutyCycle = 0;

    while(1)
    {
        if(isAdd) {
            dutyCycle = (dutyCycle + 10 > 99) ? 100: dutyCycle + 10;

            // 设置占空比
            TIM3_SetDutyCycle(dutyCycle);
            isAdd = 0;
        }

        if(isMinus) {
            dutyCycle = (dutyCycle - 10 < 1) ? 0: dutyCycle - 10;

            // 设置占空比
            TIM3_SetDutyCycle(dutyCycle);
            isMinus = 0;
        }
    }
}
